package org.monster.context.core;

import org.monster.context.reader.tag.FilterTag;

import javax.servlet.Filter;


/**
 * 过滤器正常模式
 */
public class FilterNormalPattern implements FilterPattern {

    /**
     * 过滤器配置键值
     */
    private static final FilterConfigCache FILTER_CONFIG_CACHE = FilterConfigCache.getFilterConfigCache();

    /**
     * 装载 过滤器
     *
     * @param key       键
     * @param clazz     类
     * @param filterTag 拦截器标签
     * @throws InstantiationException 实例化异常
     * @throws IllegalAccessException 非法访问异常
     */
    @Override
    public void loadFilter(String key, Class<?> clazz, FilterTag filterTag)
            throws InstantiationException, IllegalAccessException {
        Filter filter = (Filter) clazz.newInstance();
        FILTER_CONFIG_CACHE.addFilter(key + "_" + filterTag.getFilterClass(),
                filter);
    }

}
